package com.ece.mediatheque.basededonnee;

import android.content.Context;
import android.database.DatabaseErrorHandler;
import android.database.sqlite.SQLiteDatabase;
import android.database.sqlite.SQLiteOpenHelper;

/**
 * Created by loutry on 10/22/13.
 */
public class DBHelper extends SQLiteOpenHelper{

    private static final String DATABASENAME = "miam.db";
    private static final int DATABASEVERSION = 1;

    public static final String TABLE_COMMENT = "Commentaire";
    public static final String COMMENT_ID_CONSOMMATEUR = "ID_Consommateur";
    public static final String COMMENT_DATE = "date";
    public static final String COMMENT_TEXTE = "texte";
    public static final String[] PARAMS_COMMENT = new String[] {
            COMMENT_ID_CONSOMMATEUR,
            COMMENT_DATE,
            COMMENT_TEXTE
    };

    public static final String CREATETABLE_COMMENT = "CREATE TABLE " + TABLE_COMMENT + "("
            + COMMENT_ID_CONSOMMATEUR + " INTEGER PRIMARY KEY AUTOINCREMENT, "
            + COMMENT_DATE + " TEXT, "
            + COMMENT_TEXTE + " TEXT, "
            + ")";


    public static final String TABLE_CONSOMMATEUR = "Consommateur";
    public static final String CONSOMMATEUR_ID = "ID_Consommateur";
    public static final String CONSOMMATEUR_NAME = "nom";
    public static final String CONSOMMATEUR_EMAIL = "email";
    public static final String[] PARAMS_CONSOMMATEUR = new String[] {
            CONSOMMATEUR_ID,
            CONSOMMATEUR_NAME,
            CONSOMMATEUR_EMAIL
    };

    public static final String CREATETABLE_CONSOMMATEUR = "CREATE TABLE " + TABLE_CONSOMMATEUR + "("
            + CONSOMMATEUR_ID + " INTEGER PRIMARY KEY AUTOINCREMENT, "
            + CONSOMMATEUR_NAME + " VARCHAR(255), "
            + CONSOMMATEUR_EMAIL + " VARCHAR(255), "
            + ")";


    public static final String TABLE_MENU = "Menu";
    public static final String MENU_ID = "ID_Menu";
    public static final String MENU_NAME = "nom";
    public static final String MENU_PRIX = "prix";
    public static final String MENU_DESCRIPTION = "description";
    public static final String[] PARAMS_MENU = new String[] {
            MENU_ID,
            MENU_NAME,
            MENU_PRIX,
            MENU_DESCRIPTION
    };

    public static final String CREATETABLE_MENU = "CREATE TABLE " + TABLE_MENU + "("
            + MENU_ID + " INTEGER PRIMARY KEY AUTOINCREMENT, "
            + MENU_NAME + " VARCHAR(255), "
            + MENU_PRIX + " INTEGER, "
            + MENU_DESCRIPTION + " TEXT, "
            + ")";


    public static final String TABLE_MENU_COMPOSITION = "MenuComposition";
    public static final String MENU_COMPOSITION_ID_MENU = "ID_Menu";
    public static final String MENU_COMPOSITION_ID_PLAT = "ID_Plat";
    public static final String[] PARAMS_MENU_COMPOSITION = new String[] {
            MENU_COMPOSITION_ID_MENU,
            MENU_COMPOSITION_ID_PLAT,
    };

    public static final String CREATETABLE_MENU_COMPOSITION = "CREATE TABLE " + TABLE_MENU_COMPOSITION + "("
            + MENU_COMPOSITION_ID_MENU + " INTEGER, "
            + MENU_COMPOSITION_ID_PLAT + " INTEGER, "
            + ")";

    public static final String TABLE_INGREDIENT = "Ingredient";
    public static final String INGREDIENT_ID = "ID_Ingredient";
    public static final String INGREDIENT_NAME = "nom";
    public static final String INGREDIENT_COUNTRY = "pays";
    public static final String INGREDIENT_DEP = "region";
    public static final String INGREDIENT_DESCRIPTION = "description";
    public static final String INGREDIENT_PICTURE = "photo";
    public static final String INGREDIENT_DIET = "regime"; // TODO : vérifier sur le schema de la db
    public static final String[] PARAMS_INGREDIENT = new String[] {
            INGREDIENT_ID,
            INGREDIENT_NAME,
            INGREDIENT_COUNTRY,
            INGREDIENT_DEP,
            INGREDIENT_DESCRIPTION,
            INGREDIENT_PICTURE,
            INGREDIENT_DIET,
    };

    public static final String CREATETABLE_INGREDIENT = "CREATE TABLE " + TABLE_INGREDIENT + "("
            + INGREDIENT_ID + " INTEGER PRIMARY KEY AUTOINCREMENT, "
            + INGREDIENT_NAME + " VARCHAR(255), "
            + INGREDIENT_COUNTRY + " VARCHAR(255), "
            + INGREDIENT_DEP + " VARCHAR(255), "
            + INGREDIENT_DESCRIPTION + " TEXT, "
            + INGREDIENT_PICTURE + " VARCHAR(255), "
            + INGREDIENT_DIET + " VARCHAR(255), "
            + ")";

    public static final String TABLE_RECETTE = "Recette";
    public static final String RECETTE_ID_PLAT = "ID_Plat";
    public static final String RECETTE_ID_INGREDIENT = "ID_Ingredient";
    public static final String[] PARAMS_RECETTE = new String[] {
            RECETTE_ID_PLAT,
            RECETTE_ID_INGREDIENT
    };

    public static final String CREATETABLE_RECETTE = "CREATE TABLE " + TABLE_RECETTE + "("
            + RECETTE_ID_PLAT + " INTEGER, "
            + RECETTE_ID_INGREDIENT + " INTEGER, "
            + ")";

    public static final String TABLE_PLAT = "Plat";
    public static final String PLAT_ID = "ID_Plat";
    public static final String PLAT_NAME = "nom";
    public static final String PLAT_PRICE = "prix";
    public static final String PLAT_CATEGORIE = "categorie";
    public static final String PLAT_CALORIE = "calorie";
    public static final String PLAT_PICTURE = "photo";
    public static final String PLAT_DESCRIPTION = "description";
    public static final String[] PARAMS_PLAT = new String[] {
            PLAT_ID,
            PLAT_NAME,
            PLAT_PRICE,
            PLAT_CATEGORIE,
            PLAT_CALORIE,
            PLAT_PICTURE,
            PLAT_DESCRIPTION
    };

    public static final String CREATETABLE_PLAT = "CREATE TABLE " + TABLE_PLAT + "("
            + PLAT_ID + " INTEGER PRIMARY KEY AUTOINCREMENT, "
            + PLAT_NAME + " VARCHAR(255), "
            + PLAT_PRICE + " INTEGER, "
            + PLAT_CATEGORIE + " VARCHAR(255), "
            + PLAT_CALORIE + " INTEGER, "
            + PLAT_PICTURE + " VARCHAR(255), "
            + PLAT_DESCRIPTION + " TEXT, "
            + ")";

    public static final String TABLE_SEASON = "Saison";
    public static final String SEASON_ID = "ID_Saison";
    public static final String SEASON_NAME = "nom";
    public static final String SEASON_START = "start";
    public static final String SEASON_END = "end";
    public static final String[] PARAMS_SEASON = new String[] {
            SEASON_ID,
            SEASON_NAME,
            SEASON_START,
            SEASON_END
    };

    public static final String CREATETABLE_SEASON = "CREATE TABLE " + TABLE_SEASON + "("
            + SEASON_ID + " INTEGER PRIMARY KEY AUTOINCREMENT, "
            + SEASON_NAME + " VARCHAR(255), "
            + SEASON_START + " TEXT, "
            + SEASON_END + " TEXT, "
            + ")";

    public static final String TABLE_SEASON_PLAT = "SaisonPlat";
    public static final String SEASON_PLAT_ID_PLAT = "ID_Plat";
    public static final String SEASON_PLAT_ID_SEASON = "ID_Saison";
    public static final String[] PARAMS_SEASON_PLAT = new String[] {
            SEASON_PLAT_ID_PLAT,
            SEASON_PLAT_ID_SEASON
    };

    public static final String CREATETABLE_SEASON_PLAT = "CREATE TABLE " + TABLE_SEASON_PLAT + "("
            + SEASON_PLAT_ID_PLAT + " INTEGER, "
            + SEASON_PLAT_ID_SEASON + " INTEGER, "
            + ")";

    public static final String TABLE_HORAIRE = "Horaire";
    public static final String HORAIRE_ID = "ID_Horaire";
    public static final String HORAIRE_NAME = "nom";
    public static final String HORAIRE_START = "start";
    public static final String HORAIRE_END = "end";
    public static final String[] PARAMS_HORAIRE = new String[] {
            HORAIRE_ID,
            HORAIRE_NAME,
            HORAIRE_START,
            HORAIRE_END
    };

    public static final String CREATETABLE_HORAIRE = "CREATE TABLE " + TABLE_HORAIRE + "("
            + HORAIRE_ID + " INTEGER PRIMARY KEY AUTOINCREMENT, "
            + HORAIRE_NAME + " VARCHAR(255), "
            + HORAIRE_START + " TEXT, "
            + HORAIRE_END + " TEXT, "
            + ")";

    public static final String TABLE_HORAIRE_PLAT = "HorairePlat";
    public static final String HORAIRE_PLAT_ID_PLAT = "ID_Plat";
    public static final String HORAIRE_PLAT_ID_SEASON = "ID_Horaire";
    public static final String[] PARAMS_HORAIRE_PLAT = new String[] {
            HORAIRE_PLAT_ID_PLAT,
            HORAIRE_PLAT_ID_SEASON
    };

    public static final String CREATETABLE_HORAIRE_PLAT = "CREATE TABLE " + TABLE_HORAIRE_PLAT + "("
            + HORAIRE_PLAT_ID_PLAT + " INTEGER, "
            + HORAIRE_PLAT_ID_SEASON + " INTEGER, "
            + ")";

    public DBHelper(Context context) {
        super(context, DATABASENAME, null, DATABASEVERSION);
    }

    public DBHelper(Context context, String name, SQLiteDatabase.CursorFactory factory, int version) {
        super(context, name, factory, version);
    }


    @Override
    public void onCreate(SQLiteDatabase db) {
        db.execSQL(CREATETABLE_COMMENT);
        db.execSQL(CREATETABLE_CONSOMMATEUR);
        db.execSQL(CREATETABLE_INGREDIENT);
        db.execSQL(CREATETABLE_RECETTE);
        db.execSQL(CREATETABLE_MENU);
        db.execSQL(CREATETABLE_MENU_COMPOSITION);
        db.execSQL(CREATETABLE_PLAT);
        db.execSQL(CREATETABLE_HORAIRE);
        db.execSQL(CREATETABLE_HORAIRE_PLAT);
        db.execSQL(CREATETABLE_SEASON);
        db.execSQL(CREATETABLE_SEASON_PLAT);
    }

    @Override
    public void onUpgrade(SQLiteDatabase sqLiteDatabase, int i, int i2) {
        // TODO

    }
}
